package com.lin.controller;

import com.lin.entity.Admin;
import com.lin.service.AdminService;
import com.lin.service.ApplyService;
import com.lin.utils.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;

@Controller
public class AdminController {

    @Autowired
    AdminService service;

    @Autowired
    ApplyService applyService;

    @RequestMapping("/admin")
    @ResponseBody
    public String getAdmin(){
        return service.getAdmin("admin").toString();
    }


    @RequestMapping("/admin/applyManage")
    public String applyManage(String action,String aid,String nsnum){
        ApplyDao applyDao=new ApplyDao();
        String action = req.getParameter("action");
        String aid = req.getParameter("aid");

        if("agree".equals(action)){
            int nsnum2 = Util.nullToZero(nsnum) ;
            applyDao.agree(new Object[]{nsnum2,Integer.valueOf(aid)});
        }else if("reject".equals(action)){
            String set=" set state='拒绝' where aid=?";
            applyDao.update(set,new Object[]{aid});
        }
        ArrayList<HashMap<String, String>> maps = applyDao.query(" where apply.wid=workday.wid  order by applytime desc", null);
        req.setAttribute("maps",maps);
        req.getRequestDispatcher("applyManage.jsp").forward(req,resp);
    }

}
